/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPesquisarLei.java
 *
 * Created on 24/03/2011, 20:39:06
 */
package gui;

import java.util.List;
import javax.swing.JOptionPane;
import modelo.Lei;

/**
 *
 * @author Jaedson (JKalashi)
 */
public class JanelaPesquisarLei extends javax.swing.JFrame implements UI {

    /** Creates new form JanelaPesquisarLei */
    public JanelaPesquisarLei() {
        setTitle("Pesquisar Lei");
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tituloPesquisa = new javax.swing.JLabel();
        checkBoxNumeroLei = new javax.swing.JCheckBox();
        checkBoxProcesso = new javax.swing.JCheckBox();
        checkBoxEmenta = new javax.swing.JCheckBox();
        checkBoxTexto = new javax.swing.JCheckBox();
        campoTextoNumeroLei = new javax.swing.JTextField();
        campoTextoProcesso = new javax.swing.JTextField();
        campoTextoEmenta = new javax.swing.JTextField();
        campoTextoPalavraChave = new javax.swing.JTextField();
        botaoPesquisar = new javax.swing.JButton();
        checkLeisRevogadas = new javax.swing.JCheckBox();
        botaoLimpar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Janela Pesquisar Lei");
        setResizable(false);

        tituloPesquisa.setFont(new java.awt.Font("Tahoma", 1, 18));
        tituloPesquisa.setText("Pesquisa Lei");

        checkBoxNumeroLei.setText("Nº Lei");

        checkBoxProcesso.setText("Processo");

        checkBoxEmenta.setText("Ementa");

        checkBoxTexto.setText("Texto");

        botaoPesquisar.setText("Pesquisar");
        botaoPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarActionPerformed(evt);
            }
        });

        checkLeisRevogadas.setText("Leis Revogadas");

        botaoLimpar.setText("Limpar");
        botaoLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoLimparActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(checkLeisRevogadas)
                            .addComponent(checkBoxTexto)
                            .addComponent(checkBoxEmenta)
                            .addComponent(checkBoxProcesso)
                            .addComponent(checkBoxNumeroLei))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoTextoPalavraChave, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                            .addComponent(campoTextoEmenta, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                            .addComponent(campoTextoProcesso, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                            .addComponent(campoTextoNumeroLei, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(226, 226, 226)
                        .addComponent(tituloPesquisa)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(406, Short.MAX_VALUE)
                .addComponent(botaoPesquisar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tituloPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkBoxNumeroLei)
                    .addComponent(campoTextoNumeroLei, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoTextoProcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(checkBoxProcesso))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoTextoEmenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(checkBoxEmenta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkBoxTexto)
                    .addComponent(campoTextoPalavraChave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkLeisRevogadas)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoPesquisar)
                    .addComponent(botaoLimpar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPesquisarActionPerformed
        Lei lei = new Lei();

        if (checkLeisRevogadas.isSelected()) {
            controladorPesquisaLei.pesquisar();
        } else {

            if (checkBoxEmenta.isSelected()) {
                lei.setEmenta(campoTextoEmenta.getText());
            } else {
                lei.setEmenta(null);
            }

            if (checkBoxNumeroLei.isSelected()) {
                lei.setNumeroLei(campoTextoNumeroLei.getText());
            } else {
                lei.setNumeroLei(null);
            }
            if (checkBoxTexto.isSelected()) {
                lei.setTexto(campoTextoPalavraChave.getText());
            } else {
                lei.setTexto(null);
            }
            if (checkBoxProcesso.isSelected()) {
                lei.setProcesso(campoTextoProcesso.getText());
            } else {
                lei.setProcesso(null);
            }

            if (controladorPesquisaLei.existObject(lei)) {
                controladorPesquisaLei.pesquisar(lei);
                janelaResultadoPesquisa.setVisible(true);
            }else{
                exibirMensagemErro("Não existe uma lei cadastrada com estes critérios de busca");
            }
        }
    }//GEN-LAST:event_botaoPesquisarActionPerformed

    private void botaoLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoLimparActionPerformed
        limparTela();
    }//GEN-LAST:event_botaoLimparActionPerformed

    public void setControlador(Controlador c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setControladorPesquisaLei(Controlador controladorPesquisaLei) {
        this.controladorPesquisaLei = controladorPesquisaLei;
    }

    public void setJanelaResultadoPesquisa(JanelaResultadoPesquisa jrp) {
        janelaResultadoPesquisa = jrp;
    }

    public void setControladorJanelaResultadoPesquisa(Controlador controladorPesquisaLei) {
        controladorPesquisaLei.setJanelaResultado(janelaResultadoPesquisa);
    }

    public Controlador getControlador() {
        return controladorPesquisaLei;
    }

    public void exibirMensagem(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem);
    }

    public void exibirMensagemErro(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem, "Erro!", JOptionPane.ERROR_MESSAGE);
    }

    public void mostrarObjeto(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mostrarObjetos(List l) {
        //controlador.pesquisar(l);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoLimpar;
    private javax.swing.JButton botaoPesquisar;
    private javax.swing.JTextField campoTextoEmenta;
    private javax.swing.JTextField campoTextoNumeroLei;
    private javax.swing.JTextField campoTextoPalavraChave;
    private javax.swing.JTextField campoTextoProcesso;
    private javax.swing.JCheckBox checkBoxEmenta;
    private javax.swing.JCheckBox checkBoxNumeroLei;
    private javax.swing.JCheckBox checkBoxProcesso;
    private javax.swing.JCheckBox checkBoxTexto;
    private javax.swing.JCheckBox checkLeisRevogadas;
    private javax.swing.JLabel tituloPesquisa;
    // End of variables declaration//GEN-END:variables
    private Controlador controladorPesquisaLei;
    private JanelaResultadoPesquisa janelaResultadoPesquisa;

    public void limparTela() {
        campoTextoEmenta.setText(null);
        campoTextoNumeroLei.setText(null);
        campoTextoPalavraChave.setText(null);
        campoTextoProcesso.setText(null);
        checkBoxEmenta.setSelected(false);
        checkBoxNumeroLei.setSelected(false);
        checkBoxProcesso.setSelected(false);
        checkBoxTexto.setSelected(false);
        checkLeisRevogadas.setSelected(false);
    }
}
